import org.eclipse.swt.widgets.TableItem;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class NodeModel {
	private String put;
	private String id;
	private int top;
	private int left;
	private int height;
	private int width;
	private String name;
	private int kind;
	private int capitaltype;
	private int maxlen;
	private int minlen;
	private String label;

	public String getPut() {
		return put;
	}

	public void setPut(String put) {
		this.put = put;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getTop() {
		return top;
	}

	public void setTop(int top) {
		this.top = top;
	}

	public int getLeft() {
		return left;
	}

	public void setLeft(int left) {
		this.left = left;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public int getKind() {
		return kind;
	}

	public int getCapitaltype() {
		return capitaltype;
	}

	public void setKind(int kind) {
		this.kind = kind;
	}

	public void setCapitaltype(int capitaltype) {
		this.capitaltype = capitaltype;
	}

	public int getMaxlen() {
		return maxlen;
	}

	public int getMinlen() {
		return minlen;
	}

	public void setMaxlen(int maxlen) {
		this.maxlen = maxlen;
	}

	public void setMinlen(int minlen) {
		this.minlen = minlen;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getLabel() {
		return label;
	}

	public NodeModel(Node node) {
		setName(node.getNodeName());
		NamedNodeMap nodeMap = node.getAttributes();
		top = -1;
		left = -1;
		height = -1;
		width = -1;
		maxlen = -1;
		minlen = 0;
		kind = 0;
		capitaltype = 0;
		setId(nodeMap.getNamedItem(PropertyClass.id).getNodeValue());
		if (getName().equals(ComponentClass.window)) {
			return;
		}
		setPut(nodeMap.getNamedItem(PropertyClass.put).getNodeValue());
		if (getName().equals(ComponentClass.text)) {
			if (nodeMap.getNamedItem(PropertyClass.kind) != null) {
				String ki = nodeMap.getNamedItem(PropertyClass.kind)
						.getNodeValue();
				setKind(Integer.parseInt(ki));
			}
			if (nodeMap.getNamedItem(PropertyClass.capitaltype) != null) {
				String ca = nodeMap.getNamedItem(PropertyClass.capitaltype)
						.getNodeValue();
				setCapitaltype(Integer.parseInt(ca));
			}
		}
		try {
			if (getPut().indexOf(Const.LIST) < 0) {
				top = Integer.valueOf(
						nodeMap.getNamedItem(PropertyClass.top).getNodeValue())
						.intValue();
				left = Integer
						.valueOf(
								nodeMap.getNamedItem(PropertyClass.left)
										.getNodeValue()).intValue();
				height = Integer.valueOf(
						nodeMap.getNamedItem(PropertyClass.height)
								.getNodeValue()).intValue();
			}
			width = Integer.valueOf(
					nodeMap.getNamedItem(PropertyClass.width).getNodeValue())
					.intValue();
			maxlen = Integer.valueOf(
					nodeMap.getNamedItem(PropertyClass.maxlen).getNodeValue())
					.intValue();
			minlen = Integer.valueOf(
					nodeMap.getNamedItem(PropertyClass.minlen).getNodeValue())
					.intValue();
		} catch (Exception e) {
		}
	}

	public NodeModel(TableItem item) {
		for (int j = 0; j < item.getParent().getColumnCount(); j++) {
			String property = item.getParent().getColumn(j).getText();
			if (property.equals(PropertyClass.id)) {
				id = item.getText(j);
			} else if (property.equals(PropertyClass.maxlen)) {
				if (item.getText(j) == null || item.getText(j) == "") {
					maxlen = -1;
				} else {
					maxlen = Integer.parseInt(item.getText(j));
				}
			} else if (property.equals(PropertyClass.minlen)) {
				if (item.getText(j) == null || item.getText(j) == "") {
					minlen = 0;
				} else {
					minlen = Integer.parseInt(item.getText(j));
				}
			} else if (property.equals(PropertyClass.kind)) {
				if (item.getText(j) == null || item.getText(j) == "") {
					kind = 0;
				} else {
					kind = Integer.parseInt(item.getText(j));
				}
			} else if (property.equals(PropertyClass.capitaltype)) {
				if (item.getText(j) == null || item.getText(j) == "") {
					capitaltype = 0;
				} else {
					capitaltype = Integer.parseInt(item.getText(j));
				}
			} else if (property.equals(PropertyClass.data)) {
				label = item.getText(j);
			} else if (property.equals(PropertyClass.header)
					&& item.getText(j).length() > 0) {
				label = item.getText(j);
			} else if (property.equals(PropertyClass.put)) {
				put = item.getText(j);
			}
		}
	}
}
